<?php

 /**
  * @package JooS
  * @subpackage CodeGenerator
  */

  require_once "JooS/CodeGenerator/Abstract.php";

  class JooS_CodeGenerator_Parameter extends JooS_CodeGenerator_Abstract {
    /**
     * @var mixed
     */
    private $_defaultValue = null;

    /**
     * @var bool
     */
    private $_defaultValuePresent = false;

    /**
     * @var string
     */
    private $_type = null;

    /**
     * @var bool
     */
    private $_typePresent = false;

    /**
     * @param string $name
     */
    protected function __construct($name) {
      parent::__construct($name);

      $this->unsetDefaultValue();
      $this->unsetType();
    }

    /**
     * @return string
     */
    public function compile() {
      $PHPCode = "\$" . $this->getName();

      if ($this->issetDefaultValue()) {
        $PHPCode .= " = " . var_export($this->getDefautValue(), true);
      }
      if ($this->issetType()) {
        $PHPCode = $this->getType() . " " . $PHPCode;
      }

      return $PHPCode;
    }

    /**
     * @param string $className
     * @return JooS_CodeGenerator_Parameter
     */
    public static function newInstance($className) {
      return new self($className);
    }

    /**
     * @return string
     */
    public function getType() {
      return $this->_type;
    }

    /**
     * @param string $type
     * @return JooS_CodeGenerator_Parameter
     */
    public function setType($type) {
      $this->_type = $type;
      $this->_typePresent = true;

      return $this;
    }

    /**
     * @return JooS_CodeGenerator_Parameter
     */
    public function unsetType() {
      $this->_type = null;
      $this->_typePresent = false;
      return $this;
    }

    /**
     * @return bool
     */
    public function issetType() {
      return $this->_typePresent;
    }

    /**
     * @return mixed
     */
    public function getDefautValue() {
      return $this->_defaultValue;
    }

    /**
     * @param mixed $defautValue
     * @return JooS_CodeGenerator_Parameter
     */
    public function setDefaultValue($defautValue) {
      $this->_defaultValue = $defautValue;
      $this->_defaultValuePresent = true;
      return $this;
    }

    /**
     * @return JooS_CodeGenerator_Parameter
     */
    public function unsetDefaultValue() {
      $this->_defaultValue = null;
      $this->_defaultValuePresent = false;
      return $this;
    }

    /**
     * @return bool
     */
    public function issetDefaultValue() {
      return $this->_defaultValuePresent;
    }
  }
